from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

driver = webdriver.Chrome(options=options)
driver.get(r'https://www.baidu.com/')
driver.maximize_window()
sleep(1)

driver.find_element(By.ID, 's-usersetting-top').click()
driver.find_element(By.LINK_TEXT, '搜索设置').click()
sleep(1)

driver.find_element(By.XPATH, '//*[@id="wrapper"]/div[6]/div/div/ul/li[2]').click()
driver.find_element(By.XPATH, '//*[@id="adv-setting-gpc"]/div/div[1]/span').click()
# 通过xpath定位菜单值
# driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[3]').click()
# 通过找到父级唯一属性，再定位菜单值
ele = driver.find_element(By.ID, 'adv-setting-gpc')
ele.find_elements(By.XPATH, '//p[@class="c-select-item"]')[2].click()

sleep(10)
driver.quit()
